﻿using LowB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LowB.Dao
{
    public class LowBInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<LowBContext>
    {
        protected override void Seed(LowBContext context)
        {
            var users = new List<User>
             {
                 new User{ UserID="ZIY000000001",UserName="admin", Password="123456", Email="2758096202@qq.com", Sex=0,CreateUser="yuanp", CreateTime=DateTime.Now },
                 new User{ UserID="ZIY000000002",UserName="yuanp", Password="123456", Email="2758096202@qq.com", Sex=0,CreateUser="yuanp", CreateTime=DateTime.Now },
                 new User{ UserID="ZIY000000003",UserName="wangal", Password="123456", Email="244341474@qq.com", Phone="13176705605", Sex=0,CreateUser="yuanp", CreateTime=DateTime.Now },
             };
            users.ForEach(s => context.Users.Add(s));
            context.SaveChanges();

            var roles = new List<Role>
             {
                 new Role{RoleID="JS001", RoleName="管理员", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Role{RoleID="JS002", RoleName="会员用户", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Role{RoleID="JS003", RoleName="普通用户", CreateUser="yuanp", CreateTime=DateTime.Now}
             };
            roles.ForEach(s => context.Roles.Add(s));
            context.SaveChanges();


            var menus = new List<Menu>
             {
                 new Menu{MenuID="01", MenuName="系统维护", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0101", MenuName="系统参数管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0102", MenuName="系统角色管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0103", MenuName="系统用户管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0104", MenuName="系统菜单管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0105", MenuName="用户角色管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="02", MenuName="业务管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0201", MenuName="文章类别管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0202", MenuName="文章内容管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="0203", MenuName="友情链接管理", CreateUser="yuanp", CreateTime=DateTime.Now},
                 new Menu{MenuID="03", MenuName="运维分析", CreateUser="yuanp", CreateTime=DateTime.Now}
             };
            menus.ForEach(s => context.Menus.Add(s));
            context.SaveChanges();

            var userRoles = new List<UserRole>
             {
                 new UserRole{UserID="ZIY000000001", RoleID="JS001" },
                 new UserRole{UserID="ZIY000000002", RoleID="JS002" },
                 new UserRole{UserID="ZIY000000003", RoleID="JS003" }
             };
            userRoles.ForEach(s => context.UserRoles.Add(s));
            context.SaveChanges();

            var roleMenus = new List<RoleMenu>
             {
                 new RoleMenu{RoleID="JS001", MenuID="01" },
                 new RoleMenu{RoleID="JS001", MenuID="0101" },
                 new RoleMenu{RoleID="JS001", MenuID="0102" },
                 new RoleMenu{RoleID="JS001", MenuID="0103" },
                 new RoleMenu{RoleID="JS001", MenuID="0104" },
                 new RoleMenu{RoleID="JS001", MenuID="0105" },
                 new RoleMenu{RoleID="JS001", MenuID="02" },
                 new RoleMenu{RoleID="JS001", MenuID="0201" },
                 new RoleMenu{RoleID="JS001", MenuID="0202" },
                 new RoleMenu{RoleID="JS001", MenuID="0203" },
                 new RoleMenu{RoleID="JS001", MenuID="03" },
                 new RoleMenu{RoleID="JS002", MenuID="01" },
                 new RoleMenu{RoleID="JS002", MenuID="0101" },
                 new RoleMenu{RoleID="JS002", MenuID="0102" },
                 new RoleMenu{RoleID="JS002", MenuID="0103" },
                 new RoleMenu{RoleID="JS002", MenuID="0104" },
                 new RoleMenu{RoleID="JS002", MenuID="0105" },
                 new RoleMenu{RoleID="JS003", MenuID="02" },
                 new RoleMenu{RoleID="JS003", MenuID="0201" },
                 new RoleMenu{RoleID="JS003", MenuID="0202" },
                 new RoleMenu{RoleID="JS003", MenuID="0203" }
             };
            userRoles.ForEach(s => context.UserRoles.Add(s));
            context.SaveChanges();
        }
    }
}